package com.seemsea.utils.qrcode;

import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;

import javax.imageio.ImageIO;

import jp.sourceforge.qrcode.QRCodeDecoder;
import jp.sourceforge.qrcode.data.QRCodeImage;
import jp.sourceforge.qrcode.util.ContentConverter;

public class QrcodeDecoder {
	 /** 
     * ������ά������ 
     * @param path  ������ͼƬ��·�� 
     * @throws Exception 
     */  
    public static void qrcodeDecoder(String path) throws Exception {  
        QRCodeDecoder decoder = new QRCodeDecoder();  
        BufferedImage image = null;  
        if ( path.startsWith("http://")) {  
            image = ImageIO.read(new URL(path));  
        } else {  
            image = ImageIO.read(new File(path));  
        }  
        String decodedString = new String(decoder.decode(new J2SEImage(image)),"UTF-8");  
        decodedString = ContentConverter.convert(decodedString);  
        System.out.println("�������ݣ�"+decodedString);  
    }  
}

class J2SEImage implements QRCodeImage {  
    BufferedImage image;  
  
    public J2SEImage(BufferedImage source) {  
        this.image = source;  
    }  
  
    public int getWidth() {  
        return image.getWidth();  
    }  
  
    public int getHeight() {  
        return image.getHeight();  
    }  
  
    public int getPixel(int x, int y) {  
        return image.getRGB(x, y);  
  
    }  
}